using System;
using System.Collections.Generic;
using System.Text;
using Emlyn.Common.Data.DBUpdater;
using Emlyn.Common.Data.SqlServer.SqlManagers;

namespace Emlyn.Website.EmlynORegan.DBUpdateRules
{
    public class DUR_0020_tblEOArticle : IDBUpdaterRule
    {
        #region IDBUpdaterRule Members

        public int UpgradeFromVersion()
        {
            return 15;
        }

        public int UpgradeToVersion()
        {
            return 20;
        }

        public void PerformUpgrade()
        {
            string ltblEOArticle =
                "CREATE TABLE [dbo].[tblEOArticle] ( " +
                "	[ArticleID] [uniqueidentifier] NOT NULL , " +
                "	[ArticleCode] [char] (20) COLLATE Latin1_General_CI_AS NOT NULL , " +
                "	[ArticleName] [varchar] (255) COLLATE Latin1_General_CI_AS NOT NULL , " +
                "	[Url] [varchar] (255) COLLATE Latin1_General_CI_AS NULL , " +
                "	[ArticleContent] [text] COLLATE Latin1_General_CI_AS NOT NULL " +
                ") ";
            SqlManager.Execute(ltblEOArticle);


            string ltblEOArticlePK =
                "ALTER TABLE [dbo].[tblEOArticle] WITH NOCHECK ADD  " +
                "	CONSTRAINT [PK_tblEOArticle] PRIMARY KEY  CLUSTERED  " +
                "	( " +
                "		[ArticleID] " +
                "	)  ";
            SqlManager.Execute(ltblEOArticlePK);

            string lixArticle_ArticleCode =
                "CREATE  UNIQUE  INDEX [ixArticle_ArticleCode] " +
                " ON [dbo].[tblEOArticle]([ArticleCode]) ";
            SqlManager.Execute(lixArticle_ArticleCode);
        }

        #endregion
    }
}
